package com.jing.forum.interceptor;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class AppInterceptorConfigurer implements WebMvcConfigurer {

    // 注入自定义的登录拦截器
    @Resource
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加登录拦截器
        registry.addInterceptor(loginInterceptor)    // 添加用户登录拦截器
                .addPathPatterns("/**")              // 拦截所有请求
                .excludePathPatterns("/sign-in.html")
                .excludePathPatterns("/sign-up.html")    // 排除登录HTML
                .excludePathPatterns("/user/login")      // 排除注册HTML
                .excludePathPatterns("/user/register")    // 排除登录api接口
                .excludePathPatterns("/user/logout")      // 排除退出Api接口
                .excludePathPatterns("/swagger*/**")      // 排除登录swagger 下所有
                .excludePathPatterns("/v3*/**")           // 排除登录v3下所有,与swagger有关
                .excludePathPatterns("/dist/**")      // 排除所有静态文件
                .excludePathPatterns("/image/**")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/**.ico");
    }
}
